import { CopyOutlined } from "@ant-design/icons"

import { Toast } from "@/components/messages"
import { DICT_DEFAULT_CONFIG } from "@/constants/dict"
import { useDigital, useLocale } from "@/hooks"
import { handleNumber } from "@/utils/util"

const useMemFundsRecordColumn = () => {
	const { newFormat, formatMessage } = useLocale()
	const { renderCopyNo } = useDigital()
	const fundsOrderNo = {
		//订单号
		dataIndex: "eventId",
		title: newFormat("funds.order_no"),
		width: 280,
		align: "center",
		render: (text: string) => {
			return (
				text && (
					<div>
						{text}{" "}
						<span
							onClick={() => {
								navigator.clipboard
									.writeText(String(text))
									.then(() => {
										Toast.success(formatMessage({ id: "member.modal.success" }))
									})
									.catch(() => {
										Toast.error(formatMessage({ id: "member.modal.fail" }))
									})
							}}
							className="csp"
						>
							<CopyOutlined />
						</span>
					</div>
				)
			)
		}
	}
	const fundsThirdOrderNo = {
		//关联三方订单号
		dataIndex: "thirdOrderNo",
		title: newFormat("funds.fund_audit.connect_three_order_no"),
		width: 280,
		align: "center",
		render: (text: string, record: any) => {
			if (record.thirdOrderNo === undefined || record.thirdOrderNo === "" || record.thirdOrderNo === null) return <div>-</div>
			else
				return (
					<div>
						{record.thirdOrderNo}{" "}
						<span
							style={{ display: record.thirdOrderNo ? "inline" : "none" }}
							onClick={() => {
								navigator.clipboard
									.writeText(String(text))
									.then(() => {
										Toast.success(formatMessage({ id: "member.modal.success" }))
									})
									.catch(() => {
										Toast.error(formatMessage({ id: "member.modal.fail" }))
									})
							}}
							className="csp"
						>
							<CopyOutlined />
						</span>
					</div>
				)
		}
	}
	const fundsUserName = {
		//会员账号
		dataIndex: "userName",
		title: newFormat("label.username"),
		width: 150,
		align: "center",
		render: (text: string) => {
			return (
				text && (
					<div>
						{text}{" "}
						<span
							onClick={() => {
								navigator.clipboard
									.writeText(String(text))
									.then(() => {
										Toast.success(formatMessage({ id: "member.modal.success" }))
									})
									.catch(() => {
										Toast.error(formatMessage({ id: "member.modal.fail" }))
									})
							}}
							className="csp"
						>
							<CopyOutlined />
						</span>
					</div>
				)
			)
		}
	}
	const fundsAgentName = {
		//agent_number
		dataIndex: "userName",
		title: newFormat("label.agent_number"),
		width: 150,
		align: "center",
		render: (text: string) => {
			return (
				text && (
					<div>
						{text}{" "}
						<span
							onClick={() => {
								navigator.clipboard
									.writeText(String(text))
									.then(() => {
										Toast.success(formatMessage({ id: "member.modal.success" }))
									})
									.catch(() => {
										Toast.error(formatMessage({ id: "member.modal.fail" }))
									})
							}}
							className="csp"
						>
							<CopyOutlined />
						</span>
					</div>
				)
			)
		}
	}
	const fundsRealName = {
		//存款人姓名
		dataIndex: "realName",
		title: newFormat("funds.proxy_member_funds_record.real_name"),
		width: 150,
		align: "center",
		render: (text: string) => {
			return (
				<div>
					{text ?? "-"}{" "}
					<span
						style={{ display: text ? "inline" : "none" }}
						onClick={() => {
							navigator.clipboard
								.writeText(String(text))
								.then(() => {
									Toast.success(formatMessage({ id: "member.modal.success" }))
								})
								.catch(() => {
									Toast.error(formatMessage({ id: "member.modal.fail" }))
								})
						}}
						className="csp"
					>
						<CopyOutlined />
					</span>
				</div>
			)
		}
	}
	const fundsMerchantName = {
		//所属商户
		dataIndex: "merchantName",
		title: newFormat("common.belong_merchant"),
		width: 150,
		align: "center",
		render: (_text: any) => _text ?? "-"
	}
	const fundsAppTypeStr = {
		//订单来源
		dataIndex: "appTypeStr",
		title: newFormat("funds.proxy_member_funds_record.app_type"),
		width: 150,
		align: "center",
		render: (_text: string) => _text ?? "-"
	}
	const widrawFundsAppTypeStr = {
		//订单来源
		dataIndex: "appTypeStr",
		title: newFormat("funds.proxy_member_funds_record.app_type"),
		width: 150,
		align: "center",
		render: (_text: string, record: any) => {
			let str = "-"
			const data = Object.entries(DICT_DEFAULT_CONFIG.loginDeviceType)
			data.map((item: any) => {
				if (item[1].value == record.appType) {
					str = newFormat(item[1].label)
				}
			})
			return str
		}
	}
	const widrawFundsOrderStatusStr = {
		//订单状态
		dataIndex: "orderStatusStr",
		title: newFormat("funds.proxy_member_funds_record.order_status"),
		width: 150,
		align: "center",
		render: (_text: string, record: any) => {
			let str = "-"
			const data = Object.entries(DICT_DEFAULT_CONFIG.withdrawOrderStatus)
			data.map((item: any) => {
				if (item[1].value == record.orderStatus) {
					str = newFormat(item[1].label)
				}
			})
			return str
		}
	}

	const fundsOrderStatusStr = {
		//订单状态
		dataIndex: "orderStatusStr",
		title: newFormat("funds.proxy_member_funds_record.order_status"),
		width: 150,
		align: "center",
		render: (_text: string, record: any) => record.orderStatusStr ?? "-"
	}
	const fundsClientStatusStr = {
		//客户端状态
		dataIndex: "clientStatusStr",
		title: newFormat("funds.proxy_member_funds_record.client_state"),
		width: 150,
		align: "center",
		render: (_text: string) => _text ?? "-"
	}

	const withrawFundsClientStatusStr = {
		//客户端状态
		dataIndex: "clientStatusStr",
		title: newFormat("funds.proxy_member_funds_record.client_state"),
		width: 150,
		align: "center",
		render: (_text: string, record: any) => {
			let str = "-"
			const data = Object.entries(DICT_DEFAULT_CONFIG.withdrawClientStatus)
			data.map((item: any) => {
				if (item[1].value == record.clientStatus) {
					str = newFormat(item[1].label)
				}
			})
			return str
		}
	}
	const fundsIP = {
		//存款IP/风控层级
		dataIndex: "ip",
		title: (
			<>
				<div>{newFormat("funds.proxy_member_funds_record.deposit_ip")}</div>
				<div>{newFormat("funds.wind_control_level")}</div>
			</>
		),
		width: 200,
		align: "center",
		render: (_text: string, record: any) => (
			<div>
				{record.ip}
				<br />
				<span style={{ color: "red" }}>
					{newFormat("funds.wind_control_level")}:{record.parentProxyLevel ?? "-"}
				</span>
			</div>
		)
	}
	const fundsDeviceNo = {
		//存款设备终端/风控层级
		dataIndex: "deviceNo",
		title: (
			<>
				<div>{newFormat("funds.proxy_member_funds_record.device_no")}</div>
				<div>{newFormat("funds.wind_control_level")}</div>
			</>
		),
		width: 200,
		align: "center",
		render: (_text: string, record: any) => (
			<div>
				{renderCopyNo(record.deviceNo)}
				<br />
				<span style={{ color: "red" }}>
					{newFormat("funds.wind_control_level")}:{record.parentProxyLevel ?? "-"}
				</span>
			</div>
		)
	}

	const withdrawalFundsDeviceNo = {
		//取款设备终端/风控层级
		dataIndex: "deviceNo",
		title: (
			<>
				<div>{newFormat("funds.proxy_member_funds_record.withdrawal_terminal_numbe")}</div>
				<div>{newFormat("funds.wind_control_level")}</div>
			</>
		),
		width: 150,
		align: "center",
		render: (_text: string, record: any) => (
			<div>
				{record.deviceNo}
				<br />
				<span style={{ color: "red" }}>
					{newFormat("funds.wind_control_level")}:{record.parentProxyLevel ?? "-"}
				</span>
			</div>
		)
	}

	const fundsPaymentMerchantName = {
		//支付厂商
		dataIndex: "paymentMerchantName",
		title: newFormat("funds.thirdPeymentChannelConfig.payment_merchant_name"),
		width: 130,
		align: "center",
		render: (text: string, record: any) => record.payMerchantName ?? "-"
	}
	const fundsPayType = {
		//支付类型
		dataIndex: "payType",
		width: 130,
		title: newFormat("funds.pay_type"),
		align: "center",
		render: (text: string, record: any) => record.payTypeStr ?? "-"
	}

	const withrawFundsPayType = {
		//支付类型 ---取款
		dataIndex: "withdrawTypeStr",
		width: 130,
		title: newFormat("funds.pay_type"),
		align: "center",
		render: (text: string, record: any) => {
			if (record.withdrawType == 1) return newFormat("funds.proxy_member_funds_record.brank_card")
			if (record.withdrawType == 2) return newFormat("funds.proxy_member_funds_record.virtual_currency")
			if (record.withdrawType == 8) return newFormat("common.bmh_name")
		}
	}

	const fundsCurrency = {
		//支付币种
		dataIndex: "currency",
		title: newFormat("funds.fund_audit.pay_currency"),
		width: 130,
		align: "center",
		render: (text: string) => text ?? "-"
	}
	const fundsChannelName = {
		//通道名称
		dataIndex: "channelName",
		width: 130,
		title: newFormat("funds.channel_name"),
		align: "center",
		render: (text: string) => text ?? "-"
	}

	const bankcardNo = {
		//取款名称
		dataIndex: "bankcardNo",
		width: 150,
		title: newFormat("funds.proxy_member_funds_record.withdraw_account"),
		align: "center",
		render: (text: string, record: any) => {
			if (record.withdrawType === 1) return record.bankcardNo ?? "-"
			else if (record.withdrawType === 2 || record.withdrawType === 8) return record.usdtAddress ?? "-"
			else return "-"
		}
	}

	const bankName = {
		//取款信息
		dataIndex: "bankName",
		width: 150,
		title: newFormat("funds.proxy_member_funds_record.withdraw_info"),
		align: "center",
		render: (text: string, record: any) => {
			if (record.withdrawType === 1) return <div>{record.bankcardNo ?? "-"}</div>
			else if (record.withdrawType === 2) return <div>{record.usdtAddress ?? "-"}</div>
			else return <div>{"-"}</div>
		}
	}
	const widthrawBankName = {
		//取款信息
		dataIndex: "bankName",
		width: 150,
		title: newFormat("funds.proxy_member_funds_record.withdraw_info"),
		align: "center",
		render: (text: string, record: any) => {
			switch (record.withdrawType) {
				case 1:
					return (
						<>
							<div>{record.bankName || "-"}</div>
							<div>{record.realName || "-"}</div>
						</>
					)
					break
				case 2:
					return (
						<>
							<div>USDT</div>
							<div>{record.usdtType === 3 ? "TRC20" : record.usdtType === 2 ? "ERC20" : "-"}</div>
						</>
					)
					break
				case 8:
					if (record.usdtAddress) return <div>USDT {record.usdtAddress} </div>
					else return <div>-</div>
					break
			}
		}
	}

	const fundsOrderUSDTAmount = {
		//订单存款金额（USDT）
		dataIndex: "orderAmountPageSumUSDT",
		width: 200,
		title: newFormat("funds.fund_audit.order_save_money_usdt"),
		align: "center",
		render: (text: string, record: any) => {
			return handleNumber("$", record.orderAmountUsdt)
		}
	}

	const withrawFundsUSDTAmount = {
		//取款金额（USDT）
		dataIndex: "orderAmountUsdt",
		width: 200,
		title: newFormat("funds.proxy_member_funds_record.withdraw_order_amount_usdt"),
		align: "center",
		render: (text: string, record: any) => {
			return handleNumber("$", record.orderAmountUsdt)
		}
	}

	const fundsOrderCNYAmount = {
		//订单存款金额（CNY）
		dataIndex: "orderAmountPageSumCNY",
		width: 200,
		title: newFormat("funds.fund_audit.order_save_money_cny"),
		align: "center",
		render: (text: string, record: any) => {
			return handleNumber("¥", record.orderAmountCny)
		}
	}

	const withrawFundsCNYAmount = {
		//订单取款金额（CNY）
		dataIndex: "orderAmountCny",
		width: 200,
		title: newFormat("funds.proxy_member_funds_record.withdraw_order_amount_cny"),
		align: "center",
		render: (text: string, record: any) => {
			return handleNumber("¥", record.orderAmountCny)
		}
	}

	const fundsRealUSDTAmount = {
		//实际到账金额（USDT）
		dataIndex: "realAmountPageSumUSDT",
		width: 200,
		title: newFormat("funds.fund_audit.real_record_money_usdt"),
		align: "center",
		render: (text: string, record: any) => {
			return handleNumber("$", record.realAmountUsdt)
		}
	}

	const fundsRealCNYAmount = {
		//实际到账金额（CNY）
		dataIndex: "realAmountPageSumCNY",
		width: 200,
		title: newFormat("funds.fund_audit.real_record_money_cny"),
		align: "center",
		render: (text: string, record: any) => {
			return handleNumber("¥", record.realAmountCny)
		}
	}

	const fundsEventTime = {
		//申请时间
		dataIndex: "eventTime",
		width: 160,
		title: newFormat("funds.apply_time"),
		align: "center",
		render: (text: string) => text ?? "-"
	}

	const firstWithdrawStatus = {
		//是否首提
		dataIndex: "firstWithdrawStatus",
		width: 150,
		title: newFormat("funds.proxy_member_funds_record.first_withdraw_status"),
		align: "center",
		render: (text: string) => {
			if (text == "0") return newFormat("common.no")
			if (text == "1") return newFormat("common.yes")
		}
	}

	const bigWithdrawStatus = {
		//是否大额取款
		dataIndex: "bigWithdraw",
		width: 150,
		title: newFormat("funds.proxy_member_funds_record.is_big_withdraw_amount"),
		align: "center",
		render: (text: string) => {
			if (text == "0") return newFormat("common.no")
			if (text == "1") return newFormat("common.yes")
		}
	}

	const fundsPayTime = {
		//到账时间
		dataIndex: "payTime",
		width: 160,
		title: newFormat("funds.proxy_member_funds_record.arrive_time"),
		align: "center",
		render: (text: string, record: any) => record.payTime ?? "-"
	}

	const withrawFundsPayTime = {
		//出款时间
		dataIndex: "payTime",
		width: 160,
		title: newFormat("funds.proxy_member_funds_record.paragraph_time"),
		align: "center",
		render: (text: string) => text ?? "-"
	}

	const fundsRemark = {
		//备注
		dataIndex: "remark",
		width: 200,
		title: newFormat("common.remark"),
		align: "center",
		render: (text: string) => text ?? "-"
	}

	const auditDescRemark = {
		//后台备注
		dataIndex: "remark",
		width: 200,
		title: newFormat("funds.proxy_member_funds_record.audit_desc"),
		align: "center",
		render: (text: string) => text ?? "-"
	}

	const confirmClientDescRemark = {
		//客户端备注
		dataIndex: "remark",
		width: 200,
		title: newFormat("funds.proxy_member_funds_record.audit_client_desc"),
		align: "center",
		render: (text: string) => text ?? "-"
	}

	const withdrawalFundsIP = {
		//取款IP/风控层级
		dataIndex: "ip",
		title: (
			<>
				<div>{newFormat("funds.proxy_member_funds_record.withdrawal_ip")}</div>
				<div>{newFormat("funds.wind_control_level")}</div>
			</>
		),
		width: 150,
		align: "center",
		render: (_text: string, record: any) => (
			<div>
				{record.ip}
				<br />
				<span style={{ color: "red" }}>
					{newFormat("funds.wind_control_level")}:{record.parentProxyLevel ?? "-"}
				</span>
			</div>
		)
	}

	return {
		fundsOrderNo,
		fundsThirdOrderNo,
		fundsUserName,
		fundsRealName,
		fundsMerchantName,
		fundsAppTypeStr,
		fundsOrderStatusStr,
		fundsClientStatusStr,
		fundsIP,
		fundsDeviceNo,
		fundsPaymentMerchantName,
		fundsPayType,
		fundsCurrency,
		fundsChannelName,
		fundsOrderUSDTAmount,
		fundsOrderCNYAmount,
		fundsRealUSDTAmount,
		fundsRealCNYAmount,
		fundsEventTime,
		fundsPayTime,
		fundsRemark,
		withdrawalFundsIP,
		withdrawalFundsDeviceNo,
		bankcardNo,
		bankName,
		withrawFundsUSDTAmount,
		withrawFundsCNYAmount,
		firstWithdrawStatus,
		bigWithdrawStatus,
		withrawFundsPayTime,
		auditDescRemark,
		confirmClientDescRemark,
		withrawFundsPayType,
		widrawFundsOrderStatusStr,
		widrawFundsAppTypeStr,
		withrawFundsClientStatusStr,
		fundsAgentName,
		widthrawBankName
	}
}

export default useMemFundsRecordColumn
